import time

from base.base import BasePage
from selenium import webdriver

driver = webdriver.Chrome()


class RegisterPage(BasePage):
    quec_index_url = "https://iot.quectelcn.com/login"
    qq_mail_url = "https://mail.qq.com/"
    register_btn = ("css selector", "div[class='zhucediv']>span")
    person_type = ("xpath", "//p[contains(text(), '个人用户')]")
    company_type = ("xpath", "//p[contains(text(), '企业用户')]")
    register_inp = ("css selector", "div[class='el-input']>input")
    register_confirm = ("css selector", "span[class='el-checkbox__inner']")
    send_mail_btn = ("css selector", "div[class='btns']>button>span")
    alert_text = ("css selector", "div[role='alert']>p")
    qq_mail_login_outer_iframe = ("css selector", "iframe[class='QQMailSdkTool_login_loginBox_qq_iframe']")
    qq_mail_login_inner_iframe = ("css selector", "iframe[id='ptlogin_iframe']")
    qq_mail_plogin = ("id", "switcher_plogin")
    qq_mail_username = ("css selector", "input[id='u']")
    qq_mail_password = ("css selector", "input[id='p']")
    qq_mail_login_btn = ("css selector", "input[id='login_button']")
    qq_mail_recv_box = ("css selector", "a[id='folder_1']>b:first-child")
    qq_mail_mails_iframe = ("css selector", "[id='mainFrameContainer']>iframe")
    qq_mail_quec_mail = ("xpath", "//u[contains(text(), '移远开发者中心个人用户注册')]")
    qq_mail_qeuc_mail_click = ("link text", "点击注册")
    qq_mail_continue_access = ("link text", "继续访问")
    quec_username = ("css selector", "input[placeholder='请输入用户名']")
    quec_lastname = ("css selector", "input[placeholder='请输入名']")
    quec_password = ("css selector", "input[placeholder='请输入密码']")
    quec_firstname = ("css selector", "input[placeholder='请输入姓']")
    quec_confirm_pwd = ("css selector", "input[placeholder='请输入确认密码']")
    quec_company = ("css selector", "input[placeholder='请输入公司名称']")
    quec_mobile = ("css selector", "input[placeholder='请输入联系电话']")
    quec_country = ("css selector", "input[placeholder='请选择国家或地区']")
    quec_country_confirm = ("xpath", "//li/span[contains(text(),'中国')]")
    register_btn_1 = ("css selector", "div[class='btns']>button>span")

    def register(self, info):
        self.open(self.quec_index_url, "移远云")
        self.click(self.register_btn, "注册按钮")
        self.click(self.person_type, "个人用户")
        self.fill(self.register_inp, info["email"], "注册邮箱")
        self.click(self.register_confirm, "同意协议")
        self.click(self.send_mail_btn, "发送邮件")
        self.QQ_Mail_Click("273311172", "myb19951226.")
        self.fill(self.quec_username, info["username"], "用户名")
        self.fill(self.quec_lastname, info["lastname"], "名")
        self.fill(self.quec_password, info["password"], "密码")
        self.fill(self.quec_firstname, info["firstname"], "姓")
        self.fill(self.quec_confirm_pwd, info["confirm_pwd"], "确认密码")
        self.fill(self.quec_company, info["company"], "公司")
        self.fill(self.quec_mobile, info["mobile"], "手机号")
        self.fill(self.quec_country, info["country"], "国家")
        self.click(self.quec_country_confirm, "确认国家")
        self.click(self.register_confirm, "同意协议")
        time.sleep(10)
        # self.click(self.register_btn_1)

    def QQ_Mail_Click(self, username, password):
        self.open(self.qq_mail_url, "QQ邮箱")
        self.switch_to_iframe(self.qq_mail_login_outer_iframe, "QQ邮箱登录页外层")
        self.switch_to_iframe(self.qq_mail_login_inner_iframe, "QQ邮箱登录页里层")
        self.click(self.qq_mail_plogin, "账号密码登录")
        self.fill(self.qq_mail_username, username, "用户名")
        self.fill(self.qq_mail_password, password, "密码")
        self.click(self.qq_mail_login_btn, "登录")
        self.click(self.qq_mail_recv_box, "邮件箱")
        self.switch_to_iframe(self.qq_mail_mails_iframe, "QQ邮箱邮件列表")
        self.click(self.qq_mail_quec_mail, "移远注册邮件")
        self.click(self.qq_mail_qeuc_mail_click, "点击注册")
        self.switch_to_new_window()
        # self.click(self.qq_mail_continue_access)


person_info = {
    "email": "273311172@qq.com",
    "username": "fatezero",
    "lastname": "校长",
    "password": "myb19951226.",
    "firstname": "古",
    "confirm_pwd": "myb19951226.",
    "company": "No Limit",
    "mobile": "18482046076",
    "country": "中国"
}
register_obj = RegisterPage(driver)
register_obj.register(person_info)
